<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Infomation;
use App\Models\OrderFieldLog;
use App\Rep\SystemSetupRep;
use Illuminate\Http\Request;

class SystemSetup extends Controller
{
    //系统设置

    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new SystemSetupRep();
    }

    /**
     * 获取订单审核设置列表
     * @param Request $request
     */
    public function getOrderAuditList(Request $request){
        $params = $request->all();
        $data = $this->rep->getOrderAuditListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 设置订单审核状态
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function setOrderAuditStatus(Request $request){
        $params = $request->all();
        $data = $this->rep->setOrderAuditStatusRep($params);
        return re(0,$data,'success');
    }

    /**
     * 获取要显示字段
     */
    public function getOrderFieldLogList(Request $request){
        $list = OrderFieldLog::find($request->get('id'));
        return re(0,$list->field_list,'success');
    }

    /**
     * 修改要显示的字段
     */
    public function setOrderFieldLogList(Request $request){
        $model = OrderFieldLog::find($request->get('id'));
        $model->field_list = implode(',',$request->input('field_list'));
        $model->save();
        return re(0,$model,'success');
    }

    /**
     * 获取网站基本信息
     * @param Request $request
     */
    public function getInfomationList(Request $request){
        $data = Infomation::find(1);
        return re(0,$data,'success');
    }
    /**
     * 设置公司名称
     */
    public function setCompanyName(Request $request){
        $params = $request->all();
        $data = Infomation::where('id',$params['id'])->first();
        $data->company_name = $params['company_name'];
        $data->for_short = $params['for_short'];
        $data->save();
        return re(0,$data,'success');
    }

    /**
     * 获取当前版本号
     * @return \Illuminate\Http\JsonResponse
     */
    public function getCurrentVersion(){
        $data = [
            'version'=>env('CURRENT_VERSION'),
        ];
        return re(0,$data,'success');
    }

    /**
     * 获取当前公司名称
     */
    public function getCompanyName(){
        return re(0,env('COMPANY_NAME'),'success');
    }




}
